package kr.hkit.powerjava.chapter22.work3_1;

import java.util.ArrayList;
import java.util.Collections;

class JumSu {

	private ArrayList<Double> arList;

	public JumSu(ArrayList<Double> arList) {
		this.arList = arList;
	}

	public boolean range(boolean r) { 
		for (int i = 0; i < arList.size(); i++) {
			if (arList.get(i) < 0.0 || arList.get(i) > 10.0) {
				r = false;
			} else {
				r = true;
			}
		}
		return r;
	}

	public void prnRange() { 

		if (range(true)) {
			System.out.println("정상 입력 되었습니다.");
		} else {
			System.out.println("0.0~10.0까지의 값만 입력하십시오.");
		}
	}
	public double getTotal() { 
		double total = 0;
		for (int j = 0; j < arList.size(); j++) {
			if (arList.get(j) == Collections.max(arList)
					|| arList.get(j) == Collections.min(arList)) {
				continue;
			} else {
				total += arList.get(j);
			}
		}
		return total;
	}

	public double getAve() { 

		return getTotal() / (arList.size() - 2);
	}
}

public class JumsuTest {

	public static void main(String[] args) {

		ArrayList<Double> jum = new ArrayList<>();

		JumSu jum1 = new JumSu(jum);
		jum.add(9.2);
		jum.add(5.5);
		jum.add(4.8);
		jum.add(9.9);
		jum.add(7.8);
		jum.add(8.2);
		jum.add(5.3);
		jum.add(4.9);
		jum.add(8.6);
		jum.add(7.9);

		System.out.println(jum);

		jum1.prnRange();

		System.out.println();
		System.out.println("최고점("+jum.get(jum.indexOf(Collections.max(jum)))+")제외");
		System.out.println("최저점("+jum.get(jum.indexOf(Collections.min(jum)))+")제외");
		System.out.printf("총점 : " + "%4.2f" + " 점", jum1.getTotal());
		System.out.printf("\n평균 : " + "%4.2f" + " 점", jum1.getAve());
	}
}